package com.liang.pcc.service.impl;

import cn.dev33.satoken.stp.StpUtil;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.liang.pcc.domain.ExcelFile;
import com.liang.pcc.service.ExcelFileService;
import com.liang.pcc.mapper.ExcelFileMapper;
import org.springframework.stereotype.Service;

import java.util.List;

/**
* Excel文件表Service实现
*/
@Service
public class ExcelFileServiceImpl extends ServiceImpl<ExcelFileMapper, ExcelFile> implements ExcelFileService{

    @Override
    public Long getFileId(String fileName) {
        return lambdaQuery()
                .eq(ExcelFile::getFileName, fileName)
                .eq(ExcelFile::getUserAccount, StpUtil.getLoginId().toString())
                .oneOpt()
                .map(ExcelFile::getId)
                .orElse(null);
    }

    @Override
    public List<String> getFileList() {
        return lambdaQuery()
                .eq(ExcelFile::getUserAccount, StpUtil.getLoginId().toString())
                .list()
                .stream()
                .map(ExcelFile::getFileName)
                .toList();
    }
}